package com.xrit.sunnyday.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import com.xrit.sunnyday.constant.MessageConstant;
import com.xrit.sunnyday.entity.PageResult;
import com.xrit.sunnyday.entity.QueryPageBean;
import com.xrit.sunnyday.entity.Result;
import com.xrit.sunnyday.pojo.CheckItem;
import com.xrit.sunnyday.service.CheckItemService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 类名称: CheckItemController
 * 类描述:TODO
 * 创建人: czb
 * 创建时间:2022/6/8 上午 11:07
 * Version 1.0.0
 */
@RestController
@RequestMapping("checkItem")
public class CheckItemController {
    @Reference
    private CheckItemService checkItemService;
/*
查询不分页
* */
    @GetMapping("/findAll")
    public Result findAll(){
        try {
            List<CheckItem> list = checkItemService.findAll();
            return new Result(true, MessageConstant.QUERY_CHECKITEM_SUCCESS,list);
        } catch (Exception e) {
            return new Result(true, MessageConstant.QUERY_CHECKITEM_FAIL);
        }
    }
    /*查询且分页
    * */
    @PostMapping("/findPage")
    public Result findPage(@RequestBody QueryPageBean queryPageBean){
      PageInfo<CheckItem> pageInfo= checkItemService.findPage(queryPageBean);
        return new Result(true,MessageConstant.QUERY_CHECKITEM_SUCCESS,new PageResult(pageInfo.getTotal(),pageInfo.getList()));
    }
    @PostMapping("/add")
    public Result add(@RequestBody CheckItem checkItem){
       checkItemService.add(checkItem);
        return new Result(true,MessageConstant.ADD_CHECKITEM_SUCCESS);
    }
    @PostMapping("/deleteById")
    public Result deleteById(Integer id){
        checkItemService.deleteById(id);
        return new Result(true,MessageConstant.DELETE_CHECKITEM_SUCCESS);
    }
    @GetMapping("/findById")
    public Result findById(Integer id){
      CheckItem checkItem=  checkItemService.findById(id);
      return new Result(true,MessageConstant.QUERY_CHECKITEM_SUCCESS,checkItem);
    }
    @PostMapping("/update")
    public Result update(@RequestBody CheckItem checkItem){
        checkItemService.update(checkItem);
        return  new Result(true,MessageConstant.EDIT_CHECKITEM_SUCCESS);
    }
}
